package IndusmecaSI.Indusmeca_Controller
{
	import IndusmecaSI.Indusmeca_Model.Model_ListButton_Service;
	
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.core.FlexGlobals;
	
	public class Controller_ListButton
	{
		
		private var listButtonConn:Model_ListButton_Service = new Model_ListButton_Service(resultBdd,faultBdd);
		private var form:Object;
		
		public function Controller_ListButton(formSrc:Object)
		{
			form = formSrc;
		}
		public function resultBdd(type:int,result:Object):void
		{
			switch(type){
				case 1:
				{	
					trace('La liste de tous les boutons : '+result.toString());
					break;
				}
				case 2:
				{	
					trace('ListeBouton d\'un emplacement : '+result.toString());
					form.afficheBoutonBandeau(result);
					break;
				}
				case 3:
				{	
					trace('Liste bouton en fonction de son id : '+result.toString());
					break;
				}
				case 4:
				{	
					trace('Liste bouton en fonction de son id enfant'+result.toString());
					form.afficheBtnSecondaire(result);
					break;
				}
			}
		}
		public function faultBdd(str:String):void
		{
			Alert.show(str);	
		}
		public function getAllListbutton():void
		{
			listButtonConn.getAllListbutton();
		}
		public function getListbutton(id_item:int):void
		{
			listButtonConn.getListbutton(id_item);
		}
		public function getListbuttonByID():void
		{
			listButtonConn.getListbuttonByID(1);
		}
		public function getListbuttonByIDenfant(place:int,idMenuEnfant:int):void
		{
			listButtonConn.getListbuttonByIDenfant(place,idMenuEnfant);
		}
		
		/*	
		
		protected function afficheBtnPrincipal(event:ResultEvent):void
		{
		
		for( var i:int = 0; i<getListbuttonResult.lastResult.length; i++){
		var tempButton:Button = new Button();
		tempButton.id = getListbuttonResult.lastResult[i].id_button;
		tempButton.label = getListbuttonResult.lastResult[i].label_flex;
		tempButton.percentWidth = 80;
		tempButton.visible = true;	
		tempButton.uid = getListbuttonResult.lastResult[i].groupName;
		tempButton.name = getListbuttonResult.lastResult[i].stateName;
		tempButton.addEventListener(MouseEvent.CLICK,clickBtnPrincipal);
		//tempButton.toolTip = (getListbuttonResult.lastResult[i].id_menuTypeEnfant);
		groupMenu.addElement(tempButton as IVisualElement)
		var newGroup:VGroup = new VGroup();
		newGroup.id = getListbuttonResult.lastResult[i].groupName;
		newGroup.horizontalAlign = "right";
		newGroup.visible = false;
		newGroup.percentWidth = 80;
		newGroup.includeInLayout = false;		
		groupMenu.addElement(newGroup as IVisualElement);
		var id_menu_enfant:int = parseInt(getListbuttonResult.lastResult[i].id_menuTypeEnfant);
		if(tempButton.label!="Quitter"){
		getListBtnSecondaire(groupMenu.getElementIndex(newGroup),id_menu_enfant);	
		}
		}
		}
		
		protected function afficheBtnSecondaire(event:ResultEvent):void
		{
		for( var j:int = 0; j<event.result.length; j++){	
		var tempButton:Button = new Button();
		tempButton.id = event.result[j].id_button;					
		tempButton.label = event.result[j].label_flex;		
		tempButton.percentWidth = 80;
		tempButton.visible = true;	
		tempButton.uid = event.result[j].groupName;
		tempButton.name = event.result[j].stateName;
		tempButton.addEventListener(MouseEvent.CLICK,clickBtnSecondaire);
		var index:int = (ListButton)(event.result[j]).placeBtnDepart;
		groupMenu.getElementAt(index).visible = true;
		VGroup(groupMenu.getElementAt(index)).addElement(tempButton as IVisualElement);	
		}
		}
		*/
	}
}